package com.example;

import java.sql.SQLException;
import java.util.List;

public class ReassignClassesHelper {

    public static void main(String[] args) {
        UserDAO userDAO = new UserDAO();
        String[] classes = {"计算机4班", "计算机5班", "计算机6班"};
        int classIndex = 0;

        try {
            System.out.println("Starting to reassign classes for students...");
            List<User> users = userDAO.getAllUsers();
            
            for (User user : users) {
                if ("student".equals(user.getType())) {
                    // Assign student to a class in a round-robin fashion
                    String newDepartment = classes[classIndex % classes.length];
                    user.setDepartment(newDepartment);
                    userDAO.updateUser(user);
                    System.out.println("Reassigned student " + user.getUsername() + " to " + newDepartment);
                    classIndex++;
                }
            }
            System.out.println("Finished reassigning classes.");

        } catch (SQLException e) {
            e.printStackTrace();
            System.err.println("Database error during class reassignment.");
        }
    }
} 